-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC Monkey-patch history pushState and replaceState to listen to location changes #455
base: main
Are you sure you want to change the base?
POC Monkey-patch history pushState and replaceState to listen to location changes #455
Conversation
68a5305
to
2f3f8f0
Compare
@humitos this just does the monkey-patching for now (haven't added any listeners yet). Do we want to do a test-build with this, to see if it correctly picks up the "page changes", before we move on to the next step? |
2f3f8f0
to
7aee62e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a small review and left a few questions.
src/utils.js
Outdated
const originalMethod = history[methodName]; | ||
history[methodName] = function () { | ||
const result = originalMethod.apply(this, arguments); | ||
const event = new Event(methodName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is where I think we should create new Event(READTHEDOCS_URL_CHANGED)
or similar.
How hard would it be to create a simple example for this using the I tested using |
I think I can make it work locally, to develop, and then I'll ask you to do a proper test on your setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes here seem fine, no additions to the notes here 👍
I added this to the PR, but we can remove it, if you think it's redundant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
This is the first step required for the underlying work. Here, we are detecting that the URL has changed and triggering a custom event, which is 💯
The next step here is to subscribe and use this event to reload all the addons that require reloading. My idea is to investigate the usage of Lit context and make the config
object to become an object shared by that context.
With that, we can subscribe to this event, re-fetch the updated data from the endpoint and update the config
object so the addons refresh automatically.
I wasn't able to jump into exploring this idea yet, but I should probably do it soon.
@@ -24,6 +24,8 @@ export const IS_TESTING = | |||
export const IS_PRODUCTION = | |||
typeof WEBPACK_IS_PRODUCTION === "undefined" ? false : WEBPACK_IS_PRODUCTION; | |||
|
|||
export const READTHEDOCS_URL_CHANGED_EVENT = "readthedocsUrlChanged"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const READTHEDOCS_URL_CHANGED_EVENT = "readthedocsUrlChanged"; | |
export const READTHEDOCS_URL_CHANGED_EVENT = "readthedocs-url-changed"; |
We are using readthedocs-addons-data-ready
or similar for another event we are triggering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, by the way, this event should be defined in events.js
file.
history.pushState({}, "", `#url-${randomHash}`); | ||
}); | ||
|
||
window.addEventListener("readthedocsUrlChanged", (ev) => {console.log("URL Change detected!", ev)}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Closes #157